package cn.turing.firecontrol.device.rest;

import com.bw.springboot.starter.upload.model.Chunk;
import com.bw.springboot.starter.upload.service.FileService;
import com.bw.springboot.starter.upload.util.FileResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author : 赵贤
 * @create: 2023-04-04 11:19
 * @Description:
 */
@RestController
@CrossOrigin
@RequestMapping("zx2")
public class Test2Controller {

    @Resource
    private FileService fileService;

    @RequestMapping("postFileUpload")
    public Object postFileUpload(Chunk chunk) throws InterruptedException {

        fileService.postFileUpload(chunk);

        if (chunk.getTotalChunks().equals(chunk.getChunkNumber())) { //检查分块是否全部上传
            TimeUnit.SECONDS.sleep(2);
            FileResult fileResult = fileService.mergeFile(chunk);
            return fileResult;
        }
        System.out.println("文件上传成功");
        return null;
    }



}
